// import CryptoJS from 'crypto-js';
const CryptoJS = require('crypto-js')
export default class AesUtils {
	/**aes加密 */
    static encryptAes(str: string|Object) {
		if(typeof str!="string"){
			str=JSON.stringify(str)
		}
        return CryptoJS.AES.encrypt(str, "xiaobaozi").toString()
    }

    /**aes解密 */
    static decryptAes(str: string, key: string) {
        return CryptoJS.AES.decrypt(str, key).toString(CryptoJS.enc.Utf8)
    }

	/**解密并输出对象 */
	static decryptToJson(str:string){
		let jsonStr=AesUtils.decryptAes(str,"xiaobaozi")
		try {
			let json=JSON.parse(jsonStr)
			return json
		} catch (error) {
			return null
		}
	}
}
